package com.cnpc.rightslogan.controller;

import com.alibaba.fastjson.JSON;
import com.cnpc.rightslogan.entity.Organization;
import com.cnpc.rightslogan.service.IOrganizationService;
import com.cnpc.rightslogan.utils.common.BaseController;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Administrator on 2017/9/13.
 * 测试服务之间调用添加了/api  /api/** 不会参与登录验证
 */
@RestController
@RequestMapping("/api/organization")
@Api("OrganizationController相关的api")
@Slf4j
public class OrganizationController extends BaseController {

    @Autowired
    private IOrganizationService organizationServiceImpl;

    @ApiOperation(value = "获取所有数据，分页获取", notes = "获取所有数据")
    @ResponseBody
    @PostMapping("/list")
    public PageInfo<Organization> getUserList(@RequestBody @ApiParam(name = "PageInfo", value = "分页对象") PageInfo pageInfo,
                                              @Validated @RequestBody @ApiParam(name = "User", value = "User对象") Organization organization) {
        log.info("获取所有数据");
        return organizationServiceImpl.getOrganizationList(pageInfo.getPageNum(), pageInfo.getPageSize(), organization);
    }

    @ApiOperation(value = "获取所有数据，分页获取", notes = "获取所有数据")
    @ResponseBody
    @PostMapping("list1")
    public PageInfo<Organization> getUserList1(@RequestBody @ApiParam(name = "map", value = "分页对象及User对象") Map map) {
        String json = JSON.toJSONString(map);
        PageInfo pageInfo = JSON.parseObject(json, PageInfo.class);
        Organization organization = JSON.parseObject(json, Organization.class);
        log.info("获取所有数据");
        return organizationServiceImpl.getOrganizationList(pageInfo.getPageNum(), pageInfo.getPageSize(), organization);
    }

    @ApiOperation(value = "获取所有数据，分页获取", notes = "获取所有数据")
    @ResponseBody
    @PostMapping("list2")
    public PageInfo<Organization> getUserList2(@RequestBody @ApiParam(name = "json", value = "分页对象及User对象json串") String json) {
        PageInfo pageInfo = JSON.parseObject(json, PageInfo.class);
        Organization organization = JSON.parseObject(json, Organization.class);
        log.info("Organization模块-获取所有数据");
        return organizationServiceImpl.getOrganizationList(pageInfo.getPageNum(), pageInfo.getPageSize(), organization);
    }
}